package com.woniuxy.consumeserver.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.consumeserver.pojo.FinanceConsume;
import com.woniuxy.consumeserver.pojo.FinancePayPlan;
import com.woniuxy.consumeserver.service.FinanceConsumeService;
import com.woniuxy.consumeserver.service.FinancePayPlanService;
import com.woniuxy.consumeserver.mapper.FinancePayPlanMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

/**
* @author 76169
* @description 针对表【finance_pay_plan】的数据库操作Service实现
* @createDate 2024-12-17 19:05:02
*/
@Service
public class FinancePayPlanServiceImpl extends ServiceImpl<FinancePayPlanMapper, FinancePayPlan>
    implements FinancePayPlanService{
    @Autowired
    private FinanceConsumeService consumeService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void rollbackPayPlan(Long userId,BigDecimal sumPrice, Long orderId) {
        //减已用金额
        consumeService.lambdaUpdate().eq(FinanceConsume::getFinanceUserId,userId)
                .setSql("finance_used_quota = finance_used_quota - " + sumPrice)
                .update();
        //删除分期数据
        lambdaUpdate().eq(FinancePayPlan::getFinanceOrderId,orderId)
                .set(FinancePayPlan::getPayPlanState,2) //0:未还 1:已还 2:已删除
                .update();
    }
}




